﻿using System;
using CDOP.Model;

namespace CDOP.UserControls
{
    public partial class UcPanelReview : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void AddObjectValues(ref MasterTable recordToFill)
        {
            recordToFill.Panel_Review_Complete = ddPanelReviewCompleted.SelectedItem.Text;
            if (txtPanelReviewDate.Text != string.Empty)
                recordToFill.Panel_Review_Date = Convert.ToDateTime(txtPanelReviewDate.Text).ToShortDateString();
            recordToFill.Death_Explained = ddDeathExplained.SelectedItem.Text;
            recordToFill.Preventability = ddPreventability.SelectedItem.Text;
            recordToFill.Modifiable_Factors = ddModifiableFactors.SelectedItem.Text;
            recordToFill.Categorisation_of_Death = ddCategorizationofDeath.SelectedItem.Text;
            recordToFill.Death_Event = ddDeathEvent.SelectedItem.Text;
            recordToFill.Maternal_Obesity = chkMatenalObesity.Checked;
            recordToFill.Co_Sleeping = chkCoSleeping.Checked;
            recordToFill.Smoking_Parent_Carer = chkSmokingParentCarer.Checked;
            recordToFill.Domestic_Abuse = chkDomesticAbuse.Checked;
            recordToFill.IVF = chkIvf.Checked;
            recordToFill.Alcohol = chkAlcohol.Checked;
            recordToFill.Late_Bookings = chkLateBookings.Checked;
            recordToFill.Consanguinity_Parents = chkConsanguinityParents.Checked;
            recordToFill.Death_SCR = ddDeathScr.SelectedItem.Text;
            recordToFill.CDOP_Recommend_SCR = ddCdopRecommendScr.SelectedItem.Text;
            recordToFill.CDOP_Instigate_SCR = ddCdopInstigateScr.SelectedItem.Text;
        }

        public void LoadObjectValues(ref MasterTable recordToFill)
        {
            if (ddPanelReviewCompleted.Items.Count == 0)
                ddPanelReviewCompleted.DataBind();
            ddPanelReviewCompleted.SelectedIndex = ddPanelReviewCompleted.Items.IndexOf(ddPanelReviewCompleted.Items.FindByText(recordToFill.Panel_Review_Complete));
            if (recordToFill.Panel_Review_Date != null)
                txtPanelReviewDate.Text = recordToFill.Panel_Review_Date.ToString();
            if (ddDeathExplained.Items.Count == 0)
                ddDeathExplained.DataBind();
            ddDeathExplained.SelectedIndex = ddDeathExplained.Items.IndexOf(ddDeathExplained.Items.FindByText(recordToFill.Death_Explained));
            if (ddPreventability.Items.Count == 0)
                ddPreventability.DataBind();
            ddPreventability.SelectedIndex = ddPreventability.Items.IndexOf(ddPreventability.Items.FindByText(recordToFill.Preventability));
            if (ddModifiableFactors.Items.Count == 0)
                ddModifiableFactors.DataBind();
            ddModifiableFactors.SelectedIndex = ddModifiableFactors.Items.IndexOf(ddModifiableFactors.Items.FindByText(recordToFill.Modifiable_Factors));
            if (ddCategorizationofDeath.Items.Count == 0)
                ddCategorizationofDeath.DataBind();
            ddCategorizationofDeath.SelectedIndex = ddCategorizationofDeath.Items.IndexOf(ddCategorizationofDeath.Items.FindByText(recordToFill.Categorisation_of_Death));
            if (ddDeathEvent.Items.Count == 0)
                ddDeathEvent.DataBind();
            ddDeathEvent.SelectedIndex = ddDeathEvent.Items.IndexOf(ddDeathEvent.Items.FindByText(recordToFill.Death_Event));
            chkMatenalObesity.Checked = recordToFill.Maternal_Obesity;
            chkCoSleeping.Checked = recordToFill.Co_Sleeping;
            chkSmokingParentCarer.Checked = recordToFill.Smoking_Parent_Carer;
            chkDomesticAbuse.Checked = recordToFill.Domestic_Abuse;
            chkIvf.Checked = recordToFill.IVF;
            chkAlcohol.Checked = recordToFill.Alcohol;
            chkLateBookings.Checked = recordToFill.Late_Bookings;
            chkConsanguinityParents.Checked = recordToFill.Consanguinity_Parents;
            if (ddDeathScr.Items.Count == 0)
                ddDeathScr.DataBind();
            ddDeathScr.SelectedIndex = ddDeathScr.Items.IndexOf(ddDeathScr.Items.FindByText(recordToFill.Death_SCR));
            if (ddCdopRecommendScr.Items.Count == 0)
                ddCdopRecommendScr.DataBind();
            ddCdopRecommendScr.SelectedIndex = ddCdopRecommendScr.Items.IndexOf(ddCdopRecommendScr.Items.FindByText(recordToFill.CDOP_Recommend_SCR));
            if (ddCdopInstigateScr.Items.Count == 0)
                ddCdopInstigateScr.DataBind();
            ddCdopInstigateScr.SelectedIndex = ddCdopInstigateScr.Items.IndexOf(ddCdopInstigateScr.Items.FindByText(recordToFill.CDOP_Instigate_SCR));
        }

        //#region Date Fill Events

        //protected void LnkBtnPanelReviewDateClick(object sender, EventArgs e)
        //{
        //    calPanelReviewDate.Visible = true;
        //}

        //protected void CalPanelReviewDateOnSelectionChanged(object sender, EventArgs e)
        //{
        //    txtPanelReviewDate.Text = calPanelReviewDate.SelectedDate.Date.ToString();
        //    calPanelReviewDate.Visible = false;
        //}

        //protected void LnkBtnScrDateClick(object sender, EventArgs e)
        //{
        //    calScrDate.Visible = true;
        //}

        //protected void CalScrDateOnSelectionChanged(object sender, EventArgs e)
        //{
        //    txtScrDate.Text = calScrDate.SelectedDate.Date.ToString();
        //    calScrDate.Visible = false;
        //}
        //#endregion
    }
}